/**
 * Created by dingjie5 on 2015/12/4.
 */
function initSrearchDateNoToday(startInputid,endInputid){
    $("#"+startInputid).bind("focus",function(){
        var endDate =$("#"+endInputid).val();
        var nowDate;
        if(endDate) {
            nowDate = formartDate(formartStringToDate(endDate));
            WdatePicker({doubleCalendar: true, dateFmt: 'yyyy-MM-dd', maxDate: nowDate})
        }else{
            WdatePicker({doubleCalendar: true, dateFmt: 'yyyy-MM-dd'})
        }

    });
    $("#"+endInputid).bind("focus",function(){
        var startDate =$("#"+startInputid).val();
        var sDate;
        today =formartDate(new Date());
        if(startDate){
            sDate =formartDate(formartStringToDate(startDate));
            WdatePicker({doubleCalendar:true,dateFmt:'yyyy-MM-dd',minDate:sDate})
        }else{
            WdatePicker({doubleCalendar:true,dateFmt:'yyyy-MM-dd'})
        }
    });
}
function initSrearchDateMaxToday(startInputid,endInputid){
    $("#"+startInputid).bind("focus",function(){
        var endDate =$("#"+endInputid).val();
        var nowDate,today;
        today =formartDate(new Date());
        if(endDate){
            nowDate =formartDate(formartStringToDate(endDate));
            WdatePicker({doubleCalendar:true,dateFmt:'yyyy-MM-dd',maxDate:nowDate})
        }else{
            WdatePicker({doubleCalendar:true,dateFmt:'yyyy-MM-dd',maxDate:today})
        }
    });
    $("#"+endInputid).bind("focus",function(){
        var startDate =$("#"+startInputid).val();
        var sDate,today;
        today =formartDate(new Date());
        if(startDate){
            sDate =formartDate(formartStringToDate(startDate));
            WdatePicker({doubleCalendar:true,dateFmt:'yyyy-MM-dd',minDate:sDate,maxDate:today})
        }else{
            WdatePicker({doubleCalendar:true,dateFmt:'yyyy-MM-dd',maxDate:today})
        }
    });
}
function formartDate(date){
    var seperator1 = "-";
    var seperator2 = ":";
    var year = date.getFullYear();
    var month = date.getMonth()+1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}
function formartStringToDate(datestring){
    var dateArray =datestring.split(" ")[0].split("-");
    var date =new Date(dateArray[0],dateArray[1]-1,dateArray[2]);
    return date;
}


function formartDateyyyyMMddHHmmss(date){
    var seperator1 = "-";
    var seperator2 = ":";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    if (hour >= 0 && hour <= 9) {
        hour = "0" + hour;
    }
    if (minute >= 0 && minute <= 9) {
        minute = "0" + minute;
    }
    if (second >= 0 && second <= 9) {
        second = "0" + second;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate
        + " " + hour + seperator2 + minute
        + seperator2 + second;
    return currentdate;
}
//浏览器验证
function isChromeBrowser()
{
    var agent = navigator.userAgent.toLowerCase() ;

    var regStr_ie = /msie [\d.]+;/gi ;
    var regStr_ff = /firefox\/[\d.]+/gi
    var regStr_chrome = /chrome\/[\d.]+/gi ;
    var regStr_saf = /safari\/[\d.]+/gi ;
//IE
    if(agent.indexOf("msie") > 0)
    {
        return false ;
    }

//firefox
    if(agent.indexOf("firefox") > 0)
    {
        return false ;
    }

//Chrome
    if(agent.indexOf("chrome") > 0)
    {
        return true ;
    }

//Safari
    if(agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0)
    {
        return false ;
    }
    return false;
}

function countDate(date1,days){
    var date =formartStringToDate(date1);
    var endDate,mseconds;
    if(isChromeBrowser()){
        mseconds=date.valueOf()+days*24*3600*1000+5000;
        endDate =new Date(mseconds);
    }else{
        mseconds =date.getTime()+days*24*3600*1000+5000;
        endDate =new Date(mseconds);
    }
    return endDate;
}
//两个日期差几天
function comparedate(sdate,edate){
    var startDate =formartStringToDate(sdate);
    var endDate = formartStringToDate(edate);
    var date3= endDate.getTime() - startDate.getTime();
    var days=Math.floor(date3/(24*3600*1000));
    return days;
}
//判断两个日期相差的小时数
function comparedateHour(date1,date2){
    var startdate =formartStringToDate(date1);
    var endDate = formartStringToDate(date2);
    var date3= endDate.getTime() - startdate.getTime();
    var days=Math.floor(date3/(3600*1000));
    return days;
}
//判断时间1是否小于等于时间2
function comparedatedeng(date1,date2){
    var startdate =formartStringToDate(date1);
    var endDate = formartStringToDate(date2);
    return startdate<=endDate;
}